<?php
/*
	Copyright (C) 2008 - 2012 Inanta Martsanto
	Inanta Martsanto (inanta@inationsoft.com)

	This file is part of NewStep Framework.

	NewStep Framework is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	NewStep Framework is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with NewStep Framework.  If not, see <http://www.gnu.org/licenses/>.
*/

namespace Inationsoft\NS\UI\Widget;

use Inationsoft\NS\UI\UI;
use Inationsoft\NS\UI\ScriptManager;
use Inationsoft\NS\UI\StyleManager;
use Inationsoft\NS\IO\Validator\ValidatorManager;

/**
 *Create rich textarea form element
 *
 *@author Inanta Martsanto <inanta@inationsoft.com>
 */
class RichTextArea extends UI {
	function __construct($name, $value = '', $placeholder = null) {
		$this->_attr['class'] = 'NS-TextArea';

		if(isset($args['class'])) { $this->_attr['class'] .= (' ' . $args['class']); unset($args['class']); }
		if(!empty($args)) $this->_attr = array_merge($this->_attr, $args);

		$this->_attr['id'] = $name;
		$this->_attr['name'] = $name;

		$scm = ScriptManager::getInstance();
		$sm = StyleManager::getInstance();
		

		if($placeholder != null) {
			$name = 'WidgetTextArea-' . $this->getUICount('WidgetTextArea');
			$this->_attr['class'] .= ' ' . $name;

			$scm->addSource(NS_JQUERY_PATH);
			$scm->addScript("$(document).ready(function() { $('.$name').addClass('NS-Widget-Placeholder').val('$placeholder').focus(function() { if (this.value == '$placeholder') { $(this).removeClass('NS-Widget-Placeholder').val(''); }; }).blur(function() { if (this.value == '') { $(this).addClass('NS-Widget-Placeholder').val('$placeholder'); }; }); });");
		}
		
		$scm->addSource(NS_JQUERY_PATH);
		$scm->addExternalSource(NS_PUBLIC_URL . '/ns/asset/rte/jquery.rte.js');
		$scm->addExternalSource(NS_PUBLIC_URL . '/ns/asset/rte/jquery.rte.tb.js');
		$scm->addScript('$(function(){$(\'#'. $name .'\').rte({ controls_rte: rte_toolbar });});');
		
		$sm->addExternalSource(NS_PUBLIC_URL . '/ns/asset/rte/jquery.rte.css');

		parent::__construct($this->constructUI('textarea', true, $value));
		
	}
}
?>